package com.itqian.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author shishuqian
 * date 2022/2/13
 * time 17:52
 * @Desc 自动字段填充
 **/
@Component
public class FillHandler implements MetaObjectHandler {

    /**
     *插入数据时填充 createTime,updateTime字段
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.fillStrategy(metaObject, "createTime", LocalDateTime.now());
        this.fillStrategy(metaObject, "updateTime", LocalDateTime.now());
    }

    /**
     *更新数据时填充 updateTime字段
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.fillStrategy(metaObject, "updateTime", LocalDateTime.now());
    }
}
